package com.zzs.team.DAO;

import com.zzs.team.Entity.TeamShow;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface LikeDao {

    @Insert("insert into favorite (userID,teamID) values(#{userID},#{teamID})")
    void addLike(String userID,Integer teamID);

    @Select("select teamID from favorite where userID = #{userID}")
    List<Integer> getUserLikes(String userID);

    @Delete("delete  from favorite where userID=#{userid} and teamID=#{teamid}")
    void cancleLike(String userid,Integer teamid);

    @Select("select * from teams where teamID in (select teamID from favorite where userID=#{userID})")
    @Results(value = {
            @Result(id=true,column = "teamID",property = "teamID"),
            @Result(column = "createTime",property = "createTime"),
            @Result(column = "schoolName",property = "schoolName"),
            @Result(column = "typeName",property = "typeName"),
            @Result(column = "reservation",property = "reservation"),
            @Result(column = "userID",property = "userID"),
            @Result(column = "AllNumber",property = "AllNumber"),
            @Result(column = "hasNumber",property = "hasNumber"),
            @Result(column = "title",property = "title"),
            @Result(column = "QQorWechat",property = "qqorWechat"),
            @Result(column = "QQorWechatText",property = "qqorWechatText"),
            @Result(column = "aim",property = "aim"),
            @Result(column = "teamInfo",property = "teamInfo"),
            @Result(column = "Request",property = "Request"),
            @Result(column = "userID",property = "user",one = @One(select = "com.zzs.team.DAO.UserDao.findUserByOpenid"))
    })
    List<TeamShow> getUserLikesTeamShow(String userID);
}
